//package com.example.demo.controller;
//
//import com.example.demo.entity.BaseInfo;
//import com.example.demo.entity.JsonResult;
//import com.example.demo.entity.WorkTable;
//import com.example.demo.service.CustomerService;
//import com.example.demo.service.MemberService;
//import com.example.demo.service.MemberServiceImpl;
//import com.example.demo.service.NotMemberService;
//import net.sf.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Date;
//import java.util.Random;
//
///**
// * Created by lsd on 2017-09-25.
// */
//@RestController
//@RequestMapping("work")
//public class WorkController {
//    @Autowired
//    CustomerService customerService;
//    @Autowired
//    MemberService memberService;
//    @Autowired
//    NotMemberService notMemberService;
//
//    @PostMapping("startWork")
//    public JsonResult startWork(WorkTable workTable){
//        JsonResult json = null;
//        Integer state = customerService.judgeState(workTable.getPhone());
//        if(state==1){
//            JSONObject js = JSONObject.fromObject(customerService.loginMemberJudge(workTable.getPhone()));
//            String type = (String) js.get("is_have");
//            if("1".equals(type)){
//                ystem.out.println(type);
//            }
//            //开通会员开始工作
//            json = memberService.startWorkMember(workTable);
//        }else if(state==0){
//            //没开通会员开始工作
//            json = notMemberService.startWorkNotMember(workTable);
//        }
//        return json;
//    }
//    /**localhost:6080/customer/updateWork?phone=18712882023&earnMoney=12
//     * 上传已经走得时间，和赚的金钱
//     * @param workTable
//     * @return
//     */
//    @PostMapping("updateWork")
//    public JsonResult updateWork(WorkTable workTable){
//        JsonResult json = null;
//        BaseInfo baseInfo = customerService.getBaseInfo();
//        Integer state = customerService.judgeState(workTable.getPhone());
//
//        if(state==1){
//            Date now = new Date(System.currentTimeMillis());
//            Date start = customerService.getStartTime(workTable.getPhone());
//            long startTime = start.getTime();
//            long nowTime = now.getTime();
//            long workTime = (nowTime-startTime)/1000;
//            workTable.setAllTime(Integer.valueOf(String.valueOf(workTime)));
//            double moneyHigh = workTime*baseInfo.getEarnPerSecondMaxMember();
//            //开通会员
//            if(moneyHigh<workTable.getEarnMoney()){
//                workTable.setEarnMoney((int) moneyHigh);
//            }
//            json = memberService.updateWorkMember(workTable);
//        }else if(state==0){
//            Date now = new Date(System.currentTimeMillis());
//            Date start = customerService.getUpdateTime(workTable.getPhone());
//            long startTime = start.getTime();
//            long nowTime = now.getTime();
//            long workTime = (nowTime-startTime)/1000;
//            workTable.setAllTime(Integer.valueOf(String.valueOf(workTime)));
//            double moneyHigh = workTime*baseInfo.getEarnPerSecondMax();
//            //没开通会员
//            if(moneyHigh<workTable.getEarnMoney()){
//                workTable.setEarnMoney((int) moneyHigh);
//            }
//            json = notMemberService.updateWorkNotMember(workTable);
//        }
//        return json;
//    }
//
//    /**localhost:6080/customer/endWork&earnMoney=5000&phone=12
//     * 结束工作
//     * @param workTable
//     * @return
//     */
//    @PostMapping("endWork")
//    public JsonResult endWork(WorkTable workTable){
//        JsonResult json = null;
//        Integer state = customerService.judgeState(workTable.getPhone());
//        if(state==1){
//            json = memberService.endWorkMember(workTable);
//        }else if(state==0){
//            //没开通会员
//            json = notMemberService.endWorkNotMember(workTable);
//        }
//        return json;
//    }
//
//
//    /**
//     * 如果断网等错误 再次登录获取
//     * @param error
//     * @return
//     */
//    @PostMapping("getError")
//    public JsonResult getError(Integer error,String phone){
//        JsonResult json = null;
//        Integer state = customerService.judgeState(phone);
//        if(state==1){
//            //开通会员开始工作
//            json = customerService.getError(error,phone);
//        }else if(state==0){
//            //没开通会员开始工作
//            json = customerService.getErrorNoMember(error,phone);
//        }
//        return json;
//    }
//    /**
//     *
//     * 进入页面前进行判断，是否还有工作未完成
//     * @param phone
//     * @return
//     */
//    @PostMapping("loginJudge")
//    public JsonResult loginJudge(String phone){
//        JsonResult json = null;
//        Integer state = customerService.judgeState(phone);
//        if(state==1){
//            //开通会员开始工作
//            json = memberService.judgeWorkMember(phone);
//        }else if(state==0){
//            //没开通会员开始工作
//            json = notMemberService.judgeWorkNotMember(phone);
//        }
//        return json;
//    }
//
//
//    private static String[] telFirst="134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153".split(",");
//    private static String getTel() {
//        int index=getNum(0,telFirst.length-1);
//        String first=telFirst[index];
//        String second=String.valueOf(getNum(1,888)+10000).substring(1);
//        String third=String.valueOf(getNum(1,9100)+10000).substring(1);
//        return first+second+third;
//    }
//    public static int getNum(int start,int end) {
//        return (int)(Math.random()*(end-start+1)+start);
//    }
//
//    @PostMapping("sace")
//    public void main() {
//        for (int i=0;i<300;i++){
//            Random rand = new Random();
//            int randNum = rand.nextInt(970)+30;
//            String phone = getTel();
//            System.out.println(phone+"=="+randNum*100);
//            memberService.save(phone,randNum*100);
//        }
//    }
//}
